package com.besall.allbase.view.activity.chipstoollevel4.protocol.DevelopParams;

import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.LOG_FILE_RESULT;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import  bb.lanxing.R;

import com.besall.allbase.view.base.BaseActivity;

import java.util.List;

public class LogListActivity extends BaseActivity<ILoglistActivity, LoglistPresenter> implements ILoglistActivity {

    private static LogListActivity instance;
    private ListView mListView;
    public String cur_title = "Log File";

    @Override
    protected LoglistPresenter createPresenter() {
        return new LoglistPresenter();
    }

    @Override
    protected void initBeforeSetContent() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.file_list;
    }

    @Override
    protected void bindView() {
        inittoolbar(cur_title);
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        List<String> data = intent.getStringArrayListExtra("a");
        mListView = (ListView) findViewById(R.id.filename);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(LogListActivity.this, R.layout.item_log_list, data);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i("TAG", "onItemClick: " + ((TextView)view).getText().toString());
                Intent result = new Intent();
                result.putExtra(LOG_FILE_RESULT, position);
                setResult(RESULT_OK, result);
                finish();
            }
        });
    }

    @Override
    protected void setInstance() {
        instance = this;
    }

    @Override
    protected void removeInstance() {
        instance = null;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if(item.getItemId() == android.R.id.home){
            finish();
        }

/*        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                break;
        }*/
        return super.onOptionsItemSelected(item);
    }



}
